package com.yjhb.android.sbz.tool;

import android.app.Activity;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.PopupWindow;

import com.yjhb.android.sbz.R;
import com.jojo.android.zxlib.tool.ZxToast;
import com.jojo.android.zxlib.view.PopupWindowUtil;

/**
 * 创建者 zx
 * 创建时间 2021/1/6 10:03
 */
public class SharePopup {
    private final String TAG = "PopupTool";


    private SharePopup() {
    }

    public static void showSharePopup(Activity context, View rootView) {
        View view = LayoutInflater.from(context).inflate(R.layout.popup_share_invitation, null, false);
        PopupWindow popupWindow = PopupWindowUtil.CreatePopupWindow(context, view);
        popupWindow.setWidth(ViewGroup.LayoutParams.MATCH_PARENT);
        popupWindow.showAtLocation(rootView, Gravity.BOTTOM, 0, 0);
        View wx_view = view.findViewById(R.id.wx_view);
        View pyq_view = view.findViewById(R.id.pyq_view);
        View qq_view = view.findViewById(R.id.qq_view);
        View link_view = view.findViewById(R.id.link_view);
        //分享至微信好友
        wx_view.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                ShareTool.getInstance().shareImgTextWx(context);
            }
        });
        //分享至朋友圈
        pyq_view.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                ShareTool.getInstance().shareImgTextPyq(context);
            }
        });

        //分享到QQ
        qq_view.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                ShareTool.getInstance().shareImgTextQQ(context);
            }
        });

        link_view.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                ShareTool.getInstance().shareLink();
                ZxToast.showINFOBottomToast("链接已复制到剪切板，快去分享给小伙伴吧~~");
            }
        });
    }


    public static void showSharePopup2(Activity activity, View rootView, int themeIndex) {
        View view = LayoutInflater.from(activity).inflate(R.layout.diglog_share, null, false);
        PopupWindow popupWindow = PopupWindowUtil.CreatePopupWindow(activity, view);
        popupWindow.setWidth(ViewGroup.LayoutParams.MATCH_PARENT);
        popupWindow.showAtLocation(rootView, Gravity.BOTTOM, 0, 0);
        View cancel = view.findViewById(R.id.cancel);
        View wx = view.findViewById(R.id.wx);
        View pyq = view.findViewById(R.id.pyq);
        View qq = view.findViewById(R.id.qq);
        View shareLink = view.findViewById(R.id.shareLink);
        View.OnClickListener listener = new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (v == cancel) {
                    popupWindow.dismiss();
                    return;
                }
                if (v == wx) {
                    ShareTool.getInstance().shareImgWx(activity, themeIndex);
                    return;
                }
                if (v == pyq) {
                    ShareTool.getInstance().shareImgPyq(activity, themeIndex);
                    return;
                }
                if (v == qq) {
                    ShareTool.getInstance().shareImgQQ(activity, themeIndex);
                    return;
                }
                if (v == shareLink) {
                    ShareTool.getInstance().shareLink();
                    ZxToast.showINFOBottomToast("链接已复制到剪切板，快去分享给小伙伴吧~~");
                    return;
                }
            }
        };
        cancel.setOnClickListener(listener);
        wx.setOnClickListener(listener);
        pyq.setOnClickListener(listener);
        qq.setOnClickListener(listener);
        shareLink.setOnClickListener(listener);

    }


}
